/**
 * 绑定手机号 
 */
function showValidatePhone(type){
	dialogBoxShadow(false);
	if(type == 1){
		document.getElementById("newValidatePhoneDiv").style.display = "";
		addMoveEvent("dialog_title_phone","dialog_content_phone");
		document.getElementById("validatePhone").style.display="";
	}else{
		callbackEnter(submitValidatePhoneForm);
		addMoveEvent("dialog_title_phone","dialog_content_phone");
		document.getElementById("oldValidatePhoneDiv").style.display = "";
		document.getElementById("validatePhone").style.display="";
		document.getElementById("validatePhoneNumber").focus();
		document.getElementById("validatePhoneNumber").value="";
		document.getElementById("validatePhoneCode").value="";
		document.getElementById("infoTips").innerHTML="";
	}
}

function closeValidatePhone(){
	dialogBoxHidden();
	if(document.getElementById("validatePhone")!=null){
		document.getElementById("validatePhone").style.display="none";
	}
	//安全中心共用层
	if(document.getElementById("securityLayer")!=null){
		document.getElementById("securityLayer").style.display = "none";
	}
}

function closeAdvance(){
    dialogBoxHidden();
    document.getElementById("advanced").style.display="none";
}

function submitValidatePhone(id){
	var phone = document.getElementById("validatePhoneNumber").value;
	var areaCode = document.getElementById("areaCode").value;
	var msgType = document.getElementById(id+"Sign").value;
	var desc='';
	//验证手机号
	if(phone.indexOf(" ")>-1){
		desc=coincommonjs21;
	}else {
		if(phone==''){
				desc=coincommonjs22; 	
			}
		else if(areaCode==86){ 
			if(!checkMobile(phone)){
				desc=coincommonjs23;	
			}
		}else if(areaCode!=86){
			if(!checkPositiveNumber(phone)){
				desc=coincommonjs23;
			}
		}
	}
	if(desc!=""){
		document.getElementById("infoTips").innerHTML="";
		document.getElementById("infoTips").innerHTML=desc;
		return;
	}else{
		document.getElementById("infoTips").innerHTML="&nbsp;";
	}
	if(msgType==1){
		document.getElementById(id).disabled = true;
		for(num=1;num<=secs;num++) {
			  window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
		}
	}
	//发送验证码之后关闭弹窗需要刷新父页面
	if(document.getElementById("refreshSingal")!=null){
		document.getElementById("refreshSingal").value = 1;
	}
	var url = "/user/sendValidateCode.do?random="+Math.round(Math.random()*100);
	var param={phone:phone,areaCode:areaCode,msgType:msgType};
	jQuery.post(url,param,function(data){
		 if(data == 0){
			 document.getElementById("infoTips").innerHTML="";
			 document.getElementById("validatePhoneNumber").disabled="true";
			 if(msgType!=1){
				 document.getElementById("msgCodeBindBtn").disabled = true;
					inputDisabledTrue("msgCodeBindBtn");
				 for(num=1;num<=secs;num++) {
					 window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
				 }
			 }
		 }else if(data == -2){
			 desc=coincommonjs23;	
			 document.getElementById("infoTips").innerHTML=desc;
		 }else if(data == -3){
			 desc=blindphonejs1;
			 document.getElementById("infoTips").innerHTML=desc;
		 }else if(data == -4){
			 desc='  ';
			 document.getElementById("infoTips").innerHTML=desc;
		 }else if(data == -20){
			 desc=smscodewrongmuchtime;	
			 document.getElementById("infoTips").innerHTML=desc;
		 }else if(data == -30){
			 desc=blindmoretime;
			 document.getElementById("infoTips").innerHTML=desc;
		 }
	});
}

function submitValidatePhoneNew(id){
    var phone = document.getElementById("validatePhoneNumber").value;
    var areaCode = document.getElementById("areaCode").value;
    var msgType = document.getElementById(id+"Sign").value;
    var desc='';
    //验证手机号
    if(phone.indexOf(" ")>-1){
        desc=coincommonjs21;
    }else {
        if(phone==''){
            desc=coincommonjs22;
        }
        else if(areaCode==86){
            if(!checkMobile(phone)){
                desc=coincommonjs23;
            }
        }else if(areaCode!=86){
            if(!checkPositiveNumber(phone)){
                desc=coincommonjs23;
            }
        }
    }
    if(desc!=""){
        document.getElementById("infoTips").innerHTML="";
        document.getElementById("infoTips").innerHTML=desc;
        return;
    }else{
        document.getElementById("infoTips").innerHTML="&nbsp;";
    }
    if(msgType==1){
        document.getElementById(id).disabled = true;
        for(num=1;num<=secs;num++) {
            window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
        }
    }
    var url = "/user/sendValidateCodeNew.do?random="+Math.round(Math.random()*100);
    var param={phone:phone,areaCode:areaCode,msgType:msgType};
    jQuery.post(url,param,function(data){
        if(data == 0){
            document.getElementById("infoTips").innerHTML="";
            document.getElementById("validatePhoneNumber").disabled="true";
            if(msgType!=1){
                document.getElementById("msgCodeBindBtn").disabled = true;
                inputDisabledTrue("msgCodeBindBtn");
                for(num=1;num<=secs;num++) {
                    window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
                }
            }
        }else if(data == -2){
            desc=coincommonjs23;
            document.getElementById("infoTips").innerHTML=desc;
        }else if(data == -3){
            desc=blindphonejs1;
            document.getElementById("infoTips").innerHTML=desc;
        }else if(data == -4){
            desc='  ';
            document.getElementById("infoTips").innerHTML=desc;
        }else if(data == -20){
            desc=smscodewrongmuchtime;
            document.getElementById("infoTips").innerHTML=desc;
        }else if(data == -30){
            desc=blindmoretime;
            document.getElementById("infoTips").innerHTML=desc;
        }
    });
}

// 发送注册短信方法，要求输入图片验证码
function regSendMessageCode(){
	var phone = document.getElementById("regPhoneNumber").value;
	var areaCode = -1;
	if(document.getElementById("areaCode")){
		areaCode = document.getElementById("areaCode").value;
	}
	if(document.getElementById("mobileAreaCode")){
		areaCode = jQuery("#mobileAreaCode").attr("codeValue");
	}
	var msgType = document.getElementById("msgCodeBindBtnSign").value;
	var ranCodeInput = document.getElementById("ranCodeInput");
	var ranCode = "";
	var noRanCode = 0;
	if(document.getElementById("noRanCode")){
		noRanCode = document.getElementById("noRanCode").value;
	}
	var desc='';
	//验证手机号
	if(phone.indexOf(" ")>-1){
		desc=coincommonjs21;
	}else {
		if(phone==''){
				desc=coincommonjs22; 	
			}
		else if(areaCode==86){ 
			if(!checkMobile(phone)){
				desc=coincommonjs23;	
			}
		}else if(areaCode!=86){
			if(!checkPositiveNumber(phone)){
				desc=coincommonjs23;
			}
		}
	}
	// 检验图片验证码
	if(desc=="" && ranCodeInput){
        ranCode = ranCodeInput.value;
		if(ranCode==null || ranCode.length==0){
			desc=get$("registerbyphone1");
		}else{
			if(ranCode.length!=4){
				desc=get$("thecodeformatincorrect");
			}
		}
	}
	
	if(desc!=""){
		if(document.getElementById("regNameResult")!=null) {
			document.getElementById("regNameResult").style.display = "block";
			document.getElementById("regNameResult").innerHTML = "";
			document.getElementById("regNameResult").innerHTML = desc;
		}
		if(document.getElementById("registerErrorTips")!=null){
			document.getElementById("registerErrorTips").innerHTML=desc;
		}
		return;
	}else{
		if(document.getElementById("regNameResult")!=null) {
			document.getElementById("regNameResult").innerHTML = "";
		}
		if(document.getElementById("registerErrorTips")!=null){
			document.getElementById("registerErrorTips").innerHTML="";
		}
	}
	
	var url = "/user/reg/sendRegisterMessageCode.do?random="+Math.round(Math.random()*100);
	var param={phone:phone,areaCode:areaCode,msgType:msgType,ranCodeInput:ranCode,noRanCode:noRanCode};
	jQuery.post(url,param,function(resultData){

		// 刷新图片验证码
//		reloadcode();
		
		var result = eval('(' + resultData + ')');
		if(result!=null){
			var data = result.resultCode;
		}else{
			var data = -200;
		}
		
		 if(data == 0){
			 desc="";
			 if(msgType!=1){
				 document.getElementById("captcha").disabled = true;
				 inputNbgDisabledTrue("captcha");
				 for(num=1;num<=secs;num++) {
					 window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
				 }
				 jQuery("#captcha").hide();
				 jQuery("#msgCodeBindBtn").show();
			 }else{
				 document.getElementById("msgCodeBindBtn").disabled = true;
				 for(num=1;num<=secs;num++) {
					 window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
				 }
			 }
		 }else if(data == -2){
			 // 频繁请求短信接口
			 desc=get$("registerbyphone2");	
		 }else if(data == -3){
			 // 非法的请求短信接口类型 msgType
			 desc="";	
		 }else if(data == -11){
			 // 手机号不合法
			 desc=coincommonjs23;	
		 }else if(data == -12){
			 // 该手机号已被使用
			 desc=blindphonejs1;
		 }else if(data == -10){
			 desc="";
		 }else if(data == -13){
			 // 图片验证码已失效
			 desc=get$("codeexpiredtryagain");
			 showCodeLiPop();
		 }else if(data == -14){
			 // 图片验证码错误
			 desc=get$("userindexjs27");
		 }else if(data == -20){
			 // 短信验证码错误次数过多，暂时冻结发送短信
			 desc=smscodewrongmuchtime;
		 }else if(data == -30){
			 // 尝试次数过多
			 desc=get$("registerbyphone4");
		 }else{
			 desc=get$("error1006");
		 }
		if(document.getElementById("regNameResult")!=null) {
			document.getElementById("regNameResult").style.display = "block";
			document.getElementById("regNameResult").innerHTML = "";
			document.getElementById("regNameResult").innerHTML = desc;
		}
		 if(document.getElementById("registerErrorTips")!=null){
			 document.getElementById("registerErrorTips").innerHTML=desc;
		 }

		if (msgType == 0)
			jQuery('#checkCodeModel').reveal().trigger('reveal:close');
		else if (msgType == 1)
			jQuery('#dialogBoxShadow').hide();
	});
}

// 新的发送短信方法，极验滑动验证码
function regSendMessageCodeGeetest(){
    var phone = document.getElementById("regPhoneNumber").value;
    var areaCode = -1;
    if(document.getElementById("areaCode")){
        areaCode = document.getElementById("areaCode").value;
    }
    if(document.getElementById("mobileAreaCode")){
        areaCode = jQuery("#mobileAreaCode").attr("codeValue");
    }
    var msgType = document.getElementById("msgCodeBindBtnSign").value;
    var desc='';
    //验证手机号
    if(phone.indexOf(" ")>-1){
        desc=coincommonjs21;
    }else {
        if(phone==''){
            desc=coincommonjs22;
        }
        else if(areaCode==86){
            if(!checkMobile(phone)){
                desc=coincommonjs23;
            }
        }else if(areaCode!=86){
            if(!checkPositiveNumber(phone)){
                desc=coincommonjs23;
            }
        }
    }

    if(desc!=""){
        if(document.getElementById("regNameResult")!=null) {
            document.getElementById("regNameResult").style.display = "block";
            document.getElementById("regNameResult").innerHTML = "";
            document.getElementById("regNameResult").innerHTML = desc;
        }
        if(document.getElementById("registerErrorTips")!=null){
            document.getElementById("registerErrorTips").innerHTML=desc;
        }
        return;
    }else{
        if(document.getElementById("regNameResult")!=null) {
            document.getElementById("regNameResult").innerHTML = "";
        }
        if(document.getElementById("registerErrorTips")!=null){
            document.getElementById("registerErrorTips").innerHTML="";
        }
    }

    var token = "";
    if(document.getElementById("token")) {
        token = document.getElementById("token").value;
    }

    var url = "/user/reg/sendRegisterMessageCodeGeetest.do?random="+Math.round(Math.random()*100);
    var param={phone:phone,areaCode:areaCode,msgType:msgType,token:token};
    jQuery.post(url,param,function(resultData){

        var result = eval('(' + resultData + ')');
        if(result!=null){
            var data = result.resultCode;
        }else{
            var data = -200;
        }
        var isMachineCheck = 1;
        if(document.getElementById("isMachineCheck")) {
            isMachineCheck = document.getElementById("isMachineCheck").value;
        }

        if(data == 0){
            // 发送成功后，就每次都需要人机校验
            if(document.getElementById("isMachineCheck")) {
                document.getElementById("isMachineCheck").value = 1;
            }
            desc="";
            if(msgType!=1){
                document.getElementById("msgCodeBindBtn").disabled = true;
                inputNbgDisabledTrue("msgCodeBindBtn");
                for(num=1;num<=secs;num++) {
                    window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
                }
            }else{
                document.getElementById("msgCodeBindBtn").disabled = true;
                for(num=1;num<=secs;num++) {
                    window.setTimeout("updateNumberBind(" + num + ")", num * 1000);
                }
            }
        }else if(data == -2){
            // 频繁请求短信接口
            desc=get$("registerbyphone2");
        }else if(data == -3){
            // 非法的请求短信接口类型 msgType
            desc="";
        }else if(data == -11){
            // 手机号不合法
            desc=coincommonjs23;
        }else if(data == -12){
            // 该手机号已被使用
            desc=blindphonejs1;
        }else if(data == -10){
            desc="";
        }else if(data == -13){
            // 验证码已失效
            desc=get$("codeexpiredtryagain");
        }else if(data == -14){
            // 验证码错误
            desc=get$("userindexjs27");
        }else if(data == -15){
            // 重新进行人机验证
            //desc=get$("phoneTimerOut");
            isMachineCheck = 1;
            if(document.getElementById("isMachineCheck")) {
                document.getElementById("isMachineCheck").value = 1;
            }
            //因为改为字符验证所以去掉
            //document.getElementById("captcha").click();
        }else if(data == -16){
            // token失效
            desc=get$("msgfailandpleaserefresh");
            var callback={okBack:function(){window.location.reload();},noBack:function(){window.location.reload();}};
            okcoinAlert(desc,null,callback,get$("refresh"));
            //token = result.token;
            //document.getElementById("token").value = token;
        }else if(data == -20){
            // 短信验证码错误次数过多，暂时冻结发送短信
            desc=smscodewrongmuchtime;
        }else if(data == -30){
            // 尝试次数过多
            desc=get$("registerbyphone4");
        }else{
            desc=get$("error1006");
        }
        // 开启极验验证码
        if(data!=0 && isMachineCheck == 1){
            document.getElementById("msgCodeBindBtn").disabled = true;
            inputNbgDisabledTrue("msgCodeBindBtn");
            jQuery(".codeLi").show();
            jQuery("#msgCodeBindBtn").hide();
        }

        if(document.getElementById("regNameResult")!=null) {
            document.getElementById("regNameResult").style.display = "block";
            document.getElementById("regNameResult").innerHTML = "";
            document.getElementById("regNameResult").innerHTML = desc;
        }
        if(document.getElementById("registerErrorTips")!=null){
            document.getElementById("registerErrorTips").innerHTML=desc;
        }
    });
}

function submitValidatePhoneForm(){
	var phone = document.getElementById("validatePhoneNumber").value;
	var code = document.getElementById("validatePhoneCode").value;
	var areaCode = document.getElementById("areaCode").value;
	var totpCode = 0;
	var desc='';
	if(phone.indexOf(" ")>-1){
		desc=coincommonjs21;
	}else {
		if(phone==''){
				desc=coincommonjs22; 	
			}
		else if(areaCode==86){ 
			if(!checkMobile(phone)){
				desc=coincommonjs23;	
			}	
		}else if(areaCode!=86){
			if(!checkPositiveNumber(phone)){
				desc=coincommonjs23;
			}
		}
	}
	if(code.indexOf(" ")>-1 || code.length !=6){
		desc=blindphonejs2;	
	}
	if(document.getElementById("totpCode") != null){
		totpCode = document.getElementById("totpCode").value;
		if(totpCode.indexOf(" ")>-1 || totpCode.length !=6){
			desc=blindphonejs3;	
		}
	}
	if(desc!=""){
		document.getElementById("infoTips").innerHTML="";
		document.getElementById("infoTips").innerHTML=desc;
		return;
	}else{
		document.getElementById("infoTips").innerHTML="&nbsp;";
	}
	
	var url = "/user/validatePhone.do?random="+Math.round(Math.random()*100);
	var param={phone:phone,code:code,totpCode:totpCode,areaCode:areaCode};
	jQuery.post(url,param,function(data){
		var result = eval('(' + data + ')');
		if(result!=null){
			if(result.resultCode == 0){
				 document.getElementById("infoTips").innerHTML="";
				 if(document.getElementById("userPhoneSpan")!=null){
					 document.getElementById("userPhoneSpan").innerHTML=phone;
				 }
				 if(document.getElementById("isEmptyPhone") !=null ){
					 document.getElementById("isEmptyPhone").value="0";
				 }
				 closeValidatePhone();
//				 document.getElementById("foreignPhoneValidate").style.display = "none";
				 if(document.getElementById("isSubUser") !=null&&document.getElementById("isSubUser").value==1){
					 window.location.reload();
				 }
				 //绑定手机（国内跳转到安全中心，国际跳转到身份认证）
				 var flag = get$("domain_siteflag");
				 if(flag==2){
					 var callback={okBack:function(){window.location.href= document.getElementById("coinMainUrl").value+"/user/foreignIndex.do?random="+Math.round(Math.random()*100);},noBack:function(){window.location.href= document.getElementById("coinMainUrl").value+"/user/foreignIndex.do?random="+Math.round(Math.random()*100);}};
					 okcoinAlert(get$("blindphonejs4com"), null, callback);
				 }else{
					 var callback={okBack:function(){window.location.href= document.getElementById("coinMainUrl").value+"/user/security.do?random="+Math.round(Math.random()*100);},noBack:function(){window.location.href= document.getElementById("coinMainUrl").value+"/user/security.do?random="+Math.round(Math.random()*100);}};
					 okcoinAlert(get$("blindphonejs4cn"), null, callback);
				 }
				 // 刷新页面
//				 window.location.reload();
			 }else if(result.resultCode == -5){
				 document.getElementById("infoTips").innerHTML=blindphonejs5;
			 }else if(result.resultCode == -6){
				 document.getElementById("infoTips").innerHTML=blindphonejs7;
			 }else if(result.resultCode == -7){
				 document.getElementById("infoTips").innerHTML=blindphonejs6;
			 }else if(result.resultCode == -9){
				 if(result.errorNum == 0){
					 document.getElementById("infoTips").innerHTML=blindphonejs8;
				 }else{
					 document.getElementById("infoTips").innerHTML=blindphonejs9+youhave+result.errorNum+chancesleft;
					 document.getElementById("validatePhoneCode").value = "";
				 }
			 }else if(result.resultCode == -11){
				 document.getElementById("infoTips").innerHTML=blindphonejs3;
			 }else if(result.resultCode == -8){
				 if(result.errorNum == 0){
					 document.getElementById("infoTips").innerHTML=blindphonejs11;
				 }else{
					 document.getElementById("infoTips").innerHTML=blindphonejs12+youhave+result.errorNum+chancesleft;
					 document.getElementById("totpCode").value = "";
				 }
			 }else if(result.resultCode == -12){
				 document.getElementById("infoTips").innerHTML=smscodeformatincorrect;
			 }
		}
	});
}

function submitValidatePhoneFormNew(symbolParam){
    var phone = document.getElementById("validatePhoneNumber").value;
    var code = document.getElementById("validatePhoneCode").value;
    var areaCode = document.getElementById("areaCode").value;
    var totpCode = 0;
    var desc='';
    if(phone.indexOf(" ")>-1){
        desc=coincommonjs21;
    }else {
        if(phone==''){
            desc=coincommonjs22;
        }
        else if(areaCode==86){
            if(!checkMobile(phone)){
                desc=coincommonjs23;
            }
        }else if(areaCode!=86){
            if(!checkPositiveNumber(phone)){
                desc=coincommonjs23;
            }
        }
    }
    if(code.indexOf(" ")>-1 || code.length !=6){
        desc=blindphonejs2;
    }
    if(document.getElementById("totpCode") != null){
        totpCode = document.getElementById("totpCode").value;
        if(totpCode.indexOf(" ")>-1 || totpCode.length !=6){
            desc=blindphonejs3;
        }
    }
    if(desc!=""){
        document.getElementById("infoTips").innerHTML="";
        document.getElementById("infoTips").innerHTML=desc;
        return;
    }else{
        document.getElementById("infoTips").innerHTML="&nbsp;";
    }

    var url = "/user/insertIdentityPhone.do?random="+Math.round(Math.random()*100);
    if(symbolParam=="-10000"){
        url = "/user/insertIddocumentPhone.do?random="+Math.round(Math.random()*100);
    }
    var param={phone:phone,code:code,totpCode:totpCode,areaCode:areaCode};
    jQuery.post(url,param,function(data){
        var result = eval('(' + data + ')');
        if(result!=null){
            if(result.resultCode == 0){
                document.getElementById("infoTips").innerHTML="";
                if(document.getElementById("userPhoneSpan")!=null){
                    document.getElementById("userPhoneSpan").innerHTML=phone;
                }
                if(document.getElementById("isEmptyPhone") !=null ){
                    document.getElementById("isEmptyPhone").value="0";
                }
                var url = "/account/withdrawBtc.do?symbol="+symbolParam;
                if(symbolParam=="-10000"){
                    url = "/user/mainlandIndex.do?symbol=-10000";
                }
                var callback={okBack:function(){window.location.href= document.getElementById("coinMainUrl").value+url;},noBack:function(){window.location.href= document.getElementById("coinMainUrl").value+url;}};
                if(symbolParam=="-10000"){
                    closeAdvance();
                }else{
                    closeValidatePhone();
                }
                okcoinAlert(blindphonejs4, null, callback);
			 }else if(result.resultCode == -5){
				 document.getElementById("infoTips").innerHTML=blindphonejs5;
			 }else if(result.resultCode == -6){
				 document.getElementById("infoTips").innerHTML=blindphonejs7;
			 }else if(result.resultCode == -7){
				 document.getElementById("infoTips").innerHTML=blindphonejs6;
			 }else if(result.resultCode == -9){
				 if(result.errorNum == 0){
					 document.getElementById("infoTips").innerHTML=blindphonejs8;
				 }else{
					 document.getElementById("infoTips").innerHTML=blindphonejs9+youhave+result.errorNum+chancesleft;
					 document.getElementById("validatePhoneCode").value = "";
				 }
			 }else if(result.resultCode == -11){
				 document.getElementById("infoTips").innerHTML=blindphonejs3;
			 }else if(result.resultCode == -8){
				 if(result.errorNum == 0){
					 document.getElementById("infoTips").innerHTML=blindphonejs11;
				 }else{
					 document.getElementById("infoTips").innerHTML=blindphonejs12+youhave+result.errorNum+chancesleft;
					 document.getElementById("totpCode").value = "";
				 }
			 }else if(result.resultCode == -12){
				 document.getElementById("infoTips").innerHTML=smscodeformatincorrect;
			 }
		}
	},"html");
}

function updateNumberBind(num) {
	if (num == secs) {
		var areaCodeInput = document.getElementById("areaCode");
        var areaCode = 86;
        if(areaCodeInput) areaCode = areaCodeInput.value;
		if(areaCode==86){
			changeBtn("msgCodeBindBtn",0);
		}else{
			changeBtn("msgCodeBindBtn",1);
		}
		
		document.getElementById("msgCodeBindBtn").disabled = false;
		inputNbgDisabledFalse("msgCodeBindBtn");
		if(document.getElementById("validatePhoneNumber")!=null){
			document.getElementById("validatePhoneNumber").disabled = false;
		}

		// 重置验验证码
		if(document.getElementById("captcha")){
			//inputNbgDisabledTrue("msgCodeBindBtn");
			jQuery("#captcha").removeAttr("disabled");
			jQuery("#msgCodeBindBtn").removeAttr("disabled");
			jQuery("#captcha").hide();
			jQuery("#msgCodeBindBtn").show();
		}
	} else {
		var printnr = secs - num;
		document.getElementById("msgCodeBindBtn").value=printnr +resendin5sec;
	}
}

/**
 * 绑定google authenticator1
 * */
function showBindAuthenticator(){
	var url = "/user/googleAuth.do?random="+Math.round(Math.random()*100);
	var param=null;
	document.getElementById("googleInfoTips").innerHTML="";
	document.getElementById("bindAuthenticatorValidateTotpCode").value = "";
	if( document.getElementById("bindAuthenticatorPhoneCode") != null ){
		document.getElementById("bindAuthenticatorPhoneCode").value = "";
	}
	jQuery.post(url,param,function(data){
		var result = eval('(' + data + ')');
		if(result!=null){
			if(result.resultCode == 0){
				document.getElementById("bindAuthenticator").style.display="";
				dialogBoxShadow(false);
				addMoveEvent("dialog_title_google","dialog_content_google");
				if(navigator.userAgent.indexOf("MSIE")>0) { 
					jQuery('#qrcode').qrcode({text:result.qecode,width:"150",height:"150",render:"table"}); 
				} else{
					jQuery('#qrcode').qrcode({text:result.qecode,width:"150",height:"150"}); 
				}
				document.getElementById("totpKey").value = result.totpKey;
				document.getElementById("bindAuthenticatorValidateTotpCode").focus();
				callbackEnter(submitValidateAuthenticatorForm);
			}
		}
	});
}

function closeBindAuthenticator(){
	dialogBoxHidden();
	if(document.getElementById("validateTotpCode") != null){
		document.getElementById("validateTotpCode").value="";
	}
	document.getElementById("qrcode").innerHTML="";
	document.getElementById("bindAuthenticator").style.display="none";
}

function securitySendMsg(){
	var type = document.getElementById("messageType").value;
	sendMsgCode2(type,"changeMsgCodeBtn");
	//sendMsgCode(type);
}

/**
 * 修改身份验证类型
 * authType 0:手机 1:google
 * bindType 1:手机不为空 2:key不为空 3:都不空
 * */
function changeAuthenticator(authType,bindType,obj){
	document.getElementById("messageType").value = 5;
	document.getElementById("changeAuthCode").onkeydown = function (e){
		callbackEnter(submitChangeAuthForm);
	};
	document.getElementById("submitBtn").onclick = submitChangeAuthForm;
	document.getElementById("changeAuthenticator").style.display="";
	dialogBoxShadow(false);
	document.getElementById("changeAuthCode").value = "";
	document.getElementById("changeAuthTips").innerHTML = "";
	addMoveEvent("dialog_title_auth","dialog_content_auth");
	if(authType == 0 && bindType ==1){
		closeChangeAuthenticator();
		okcoinAlert(blindphonejs15,null,null);
		return false;
	}else if(authType == 1 && bindType ==2){
		closeChangeAuthenticator();
		okcoinAlert(blindphonejs16,null,null);
		return false;
	}else{
		if(authType ==0){
			document.getElementById("changeAuthMsg").style.display="";
		}else{
			document.getElementById("changeAuthMsg").style.display="none";
		}
	}
	document.getElementById("msgSpan").innerHTML = blindphonejs17;
}
function closeChangeAuthenticator(){
	dialogBoxHidden();
	if(document.getElementById("changeAuthenticator")!=null){
		document.getElementById("changeAuthenticator").style.display = "none";
	}
	//安全中心共用层
	if(document.getElementById("securityLayer")!=null){
		document.getElementById("securityLayer").style.display = "none";
	}
}

function getCode(){
	var totpCode = 0;
	if(document.getElementById("userTotpCode") != null){
		totpCode = document.getElementById("userTotpCode").value;
	}
	var url = "/user/getValidateCode.do?totpCode="+totpCode+"&random="+Math.round(Math.random()*100);
	jQuery.post(url,function(data){
		if(data > 0){
			document.getElementById("resultCode").innerHTML= 'ok'+data;
		}else{
			document.getElementById("msgInfo").innerHTML=blindphonejs30;
			
		}
	});
}
function changeAreaCode(){
	var code = document.getElementById("areaCode").value;
	document.getElementById("phoneBefore").innerHTML="+"+code;
}
function changeUpdatePhoneAreaCode(){
	var code = document.getElementById("updatePhoneAreaCode").value;
	document.getElementById("phoneUpdateBefore").innerHTML="+"+code;
}

function showUpdatePhoneForm(){
	document.getElementById("updatePhoneDiv").style.display="";
	dialogBoxShadow(false);
	addMoveEvent("updatePhone_title_auth","updatePhone_content_auth");
}
function closeUpdatePhone(){
	dialogBoxHidden();
	if(document.getElementById("updatePhoneDiv")!=null){
		document.getElementById("updatePhoneDiv").style.display="none";
	}
	//安全中心共用层
	if(document.getElementById("securityLayer")!=null){
		document.getElementById("securityLayer").style.display = "none";
	}
}
function phoneBlur(){
	var mobile = document.getElementById("validatePhoneNumber").value;
	if(!checkMobile(mobile)){
		document.getElementById("updatePhoneinfoTips").innerHTML = blindphonejs31;
	}else{
		document.getElementById("updatePhoneinfoTips").innerHTML = blindphonejs31;
	}
	document.getElementById("updatePhoneinfoTips").innerHTML = " ";
}
function submitUpdatePhoneForm(){
	var oldPhoneCode = document.getElementById("oldPhoneCode").value;
	var newPhoneCode = document.getElementById("newPhoneCode").value;
	var areaCode = document.getElementById("updatePhoneAreaCode").value;
	if(oldPhoneCode == "" || oldPhoneCode.length != 6){
		document.getElementById("updatePhoneinfoTips").innerHTML = blindphonejs32;
		return;
	}
	if(newPhoneCode == "" || newPhoneCode.length != 6){
		document.getElementById("updatePhoneinfoTips").innerHTML = blindphonejs33;
		return;
	}
	
	var url = "/user/updatePhone.do?random="+Math.round(Math.random()*100);
	var param = {oldPhoneCode:oldPhoneCode,newPhoneCode:newPhoneCode,areaCode:areaCode};
	jQuery.post(url,param,function(data){
		var result = eval('(' + data + ')');
		if(result!=null){
			 if(result.resultCode == -11){
				 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs35;
			 }else if(result.resultCode == -12){
				 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs35;
			 }else if(result.resultCode == -8){
				 if(result.errorNum == 0){
					 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs36;
				 }else{
					 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs37+youhave+result.errorNum+chancesleft;
					 document.getElementById("oldPhoneCode").value = "";
				 }
			 }else if(result.resultCode == -9){
				 if(result.errorNum == 0){
					 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs36;
				 }else{
					 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs34+youhave+result.errorNum+chancesleft;
					 document.getElementById("oldPhoneCode").value = "";
				 }
			 }else if(result.resultCode == -2){
				 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs35;
			 }else if(result.resultCode == -3){
				 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs39;
			 }else if(result.resultCode == -4){
				 if(result.errorNum == 0){
					 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs36;
				 }else{
					 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs35+youhave+result.errorNum+chancesleft;
					 document.getElementById("newPhoneCode").value = "";
				 }
			 }else if(result.resultCode == -7){
				 document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs40;
			 }else if(result.resultCode == 0){
				 waitingStation("submitBtn",insubmiting);
				 closeUpdatePhone();
				var callback={okBack:function(){window.location.href= document.getElementById("coinMainUrl").value+"/user/security.do";},noBack:function(){window.location.href= document.getElementById("coinMainUrl").value+"/user/security.do";}};
                 var flag = get$("domain_siteflag");
                 if(flag == 2){
                     okcoinAlert(get$("blindphonejs41com"),null,callback);
				 }else{
                     okcoinAlert(get$("blindphonejs41cn"),null,callback);
				 }
			 }
		}
	});
}
var updatePhonesecs = 61;
function sendUpdatePhoneCode(type,id){
	if(type == 0){
		document.getElementById("updatePhoneNumber").disabled="true";
	}
	var areaCode = document.getElementById("updatePhoneAreaCode").value;
	var url = "/user/sendMsg.do?random="+Math.round(Math.random()*100);
	var msgType = document.getElementById(id+"Sign").value;
	if(msgType==1){
		//document.getElementById(id).disabled = true;
		if(type == 17){
			document.getElementById("oldmsgCodeBindBtn").disabled = true;
			inputDisabledTrue("oldmsgCodeBindBtn");
			 for(var num=1;num<=updatePhonesecs;num++) {
				  window.setTimeout("updateOldmsgCodeNumber(" + num + ")", num * 1000);
			  }
		}
		if(type == 0){
			if(document.getElementById("updatePhoneNumber")==null||document.getElementById("updatePhoneNumber").value==""){
				document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs42;
				document.getElementById("updatePhoneNumber").disabled="";
				return;
			}
			document.getElementById("newmsgCodeBindBtn").disabled = true;
			inputDisabledTrue("newmsgCodeBindBtn");
			 for(var num=1;num<=updatePhonesecs;num++) {
				  window.setTimeout("updateNewmsgCodeNumber(" + num + ")", num * 1000);
			  }
		}
	}
	var param ={type:type,areaCode:areaCode,msgType:msgType};

	if(type == 0){
		var phone = document.getElementById("updatePhoneNumber").value;
		param = {type:type,phone:phone,areaCode:areaCode,msgType:msgType};
	}
	jQuery.post(url,param,function(data){
		if(data == 0){
			if(msgType!=1){
				if(type == 17){
					document.getElementById("oldmsgCodeBindBtn").disabled = true;
					inputDisabledTrue("oldmsgCodeBindBtn");
					 for(var num=1;num<=updatePhonesecs;num++) {
						  window.setTimeout("updateOldmsgCodeNumber(" + num + ")", num * 1000);
					  }
				}
				if(type == 0){
					document.getElementById("newmsgCodeBindBtn").disabled = true;
					inputDisabledTrue("newmsgCodeBindBtn");
					 for(var num=1;num<=updatePhonesecs;num++) {
						  window.setTimeout("updateNewmsgCodeNumber(" + num + ")", num * 1000);
					  }
				}
			}
		}else if(data == -2){
			document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs43;
		}else if(data == -3){
			if(document.getElementById("updatePhoneinfoTips") != null){
				document.getElementById("updatePhoneinfoTips").style.display = "";
				document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs8;
			}
		}else if(data == -1){
			document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs44;
			document.getElementById("updatePhoneNumber").disabled="";
		}else if(data == 1){
			document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs42;
			document.getElementById("updatePhoneNumber").disabled="";
		}else if(data == 2){
			document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs31;
			document.getElementById("updatePhoneNumber").disabled="";
		}else if(data == 3){
			document.getElementById("updatePhoneinfoTips").innerHTML=blindphonejs40;
			document.getElementById("updatePhoneNumber").disabled="";
		}
	});
}

function updateOldmsgCodeNumber(num){
	if (num == updatePhonesecs) {
		var isInter = document.getElementById("isInter").value;
		changeBtn("oldmsgCodeBindBtn",isInter);
		document.getElementById("oldmsgCodeBindBtn").disabled = false;
		inputDisabledFalse("oldmsgCodeBindBtn");
	} else {
		hiddenTitle("oldmsgCodeBindBtn");
		var printnr = updatePhonesecs - num;
		document.getElementById("oldmsgCodeBindBtn").value= printnr +resendin5sec;
	}
}
function updateNewmsgCodeNumber(num){
	if (num == updatePhonesecs) {
		var isInter = document.getElementById("isInter").value;
		changeBtn("newmsgCodeBindBtn",isInter);
		document.getElementById("newmsgCodeBindBtn").disabled = false;
		inputDisabledFalse("newmsgCodeBindBtn");
	} else {
		//document.getElementById("newTitle").style.display="none";
		hiddenTitle("newmsgCodeBindBtn");
		var printnr = updatePhonesecs - num;
		document.getElementById("newmsgCodeBindBtn").value= printnr +resendin5sec;
	}
}

//新
function regRanCodeOnkeyUpRegit(obj,type){
	var ranCode = obj.value;
	var msgCodeBindBtn = document.getElementById("msgCodeBindBtn");
	var ranCodeSubmit = jQuery("#ranCodeSubmit");
	var desc='';
	
	// 判断是否存于短信1分钟冻结状态
	if(msgCodeBindBtn.value.match(/^[0-9].+$/)){
		return ;
	}
	
	if(ranCode.length<4){
		msgCodeBindBtn.disabled = true;
		inputNbgDisabledTrue("msgCodeBindBtn");
		return ;
	}else if(ranCode.length==4){
		// 校验验证码
		url = "/user/checkCaptcha.do?random="+Math.round(Math.random()*100);
		var param={ranCode:ranCode};
		jQuery.post(url,param,function(resultData){
			var result = eval('(' + resultData + ')');
			if(result!=null){
				var data = result.resultCode;
			}else{
				var data = -2;
			}
			
			if(data==1){
				desc = "";
				msgCodeBindBtn.disabled = false;
				inputNbgDisabledFalse("msgCodeBindBtn");
				if(type==1){
					jQuery(".codeLi").hide();
					dialogBoxHidden();
					jQuery("#msgCodeBindBtnA").hide();
					jQuery("#msgCodeBindBtn").show();
					ranCodeSubmit.removeAttr("disabled");
                    regSendMessageCode();
				}
			}else if(data==-1){
				desc = get$("wrongcodetryagain");
				msgCodeBindBtn.disabled = true;
				inputNbgDisabledTrue("msgCodeBindBtn");
				ranCodeSubmit.attr("disabled",true);
			}else if(data==-2){
				desc = get$("codeexpiredtryagain");
				msgCodeBindBtn.disabled = true;
				inputNbgDisabledTrue("msgCodeBindBtn");
				ranCodeSubmit.attr("disabled","true");
			}else{
				desc = get$("codeexpiredtryagain");
				msgCodeBindBtn.disabled = true;
				inputNbgDisabledTrue("msgCodeBindBtn");
				ranCodeSubmit.attr("disabled","true");
			}
			if(document.getElementById("codeLiTips")!=null){
				document.getElementById("codeLiTips").innerHTML = desc;
				window.setTimeout(function(){
					jQuery("#codeLiTips").html(" ");
				},5000);
			}
			if(document.getElementById("regNameResult")!=null && false) {
				document.getElementById("regNameResult").style.display = "block";
				document.getElementById("regNameResult").innerHTML = "";
				document.getElementById("regNameResult").innerHTML = desc;
			}
			if(document.getElementById("codeErrorTips")!=null){
				document.getElementById("codeErrorTips").innerHTML=desc;
			}
		});
		
	}else if(ranCode.length>4){
		desc = get$("thecodeformatincorrect");
		msgCodeBindBtn.disabled = true;
		inputNbgDisabledTrue("msgCodeBindBtn");
	}
	if(document.getElementById("codeLiTips")!=null){
		document.getElementById("codeLiTips").innerHTML = desc;
		window.setTimeout(function(){
			jQuery("#codeLiTips").html(" ");
		},5000);
	}
	if(document.getElementById("regNameResult")!=null && false) {
		document.getElementById("regNameResult").style.display = "block";
		document.getElementById("regNameResult").innerHTML = "";
		document.getElementById("regNameResult").innerHTML = desc;
	}
	if(document.getElementById("registerErrorTips")!=null){
		document.getElementById("registerErrorTips").innerHTML=desc;
	}

	return;
}

//注册验证码弹层

function showCodeLiPop(){
	dialogBoxShadow();
	jQuery(".codeLi").show();
}

function closeCodeLiPop(){
	dialogBoxHidden();
	jQuery(".codeLi").hide();
}

// 初始化极验验证码
function initCaptcha(config) {
	initCaptchPre(config, "captcha", "msgCodeBindBtnA", "msgCodeBindBtn", "registerErrorTip");
}

function initCaptchPre(config, btnLabelId, btnLabel, btn, errTips) {
	jQuery.post('/user/reg/initGeetest.do', {}, function(data){
		var desc = "";
		var _config = jQuery.extend({}, config);
		_config.challenge = data.challenge;
		initGeetest(_config, function (captchaObj) {
			
			captchaObj.appendTo("#"+btnLabelId); // 绑定到id为captcha的元素上

			captchaObj.bindOn("#"+btnLabelId);

			captchaObj.onSuccess(function (data) {
				// 成功回调
				jQuery.post('/user/reg/verifyGeetest.do',{
					'geetest_challenge' : jQuery("." + btnLabel + " .geetest_challenge").val(),
					'geetest_validate' : jQuery("." + btnLabel + " .geetest_validate").val(),
					'geetest_seccode' : jQuery("." + btnLabel + " .geetest_seccode").val()
				},function(data){
					if (data.indexOf('success') > -1) {
						// 验证成功，显示短信发送按钮
						desc = "";
						//window.console.log("验证成功，显示短信发送按钮");
						document.getElementById(btn).disabled = false;
						inputNbgDisabledFalse(btn);
						jQuery("#"+btnLabelId).hide();
						jQuery("#"+btn).show();

						if (jQuery("#"+btn).attr('auto-run-after-gee-test') == 'true') {
							regSendMessageCodeGeetest();
						}
					} else {
						// 验证错误，刷新验证码
						desc = "验证码出错，请重新验证";
						//window.console.log("验证码出错，请重新验证");
					}

					if(document.getElementById(errTips)!=null){
						document.getElementById(errTips).innerHTML=desc;
					}
				});
			}, 'text');

			captchaObj.getValidate(); // 获取成功后的验证信息，失败是返回false

		});
	}, 'json');
}

function initCaptchCallBack(config, btnLabelId, btnLabel, errTips, params, callback) {
    jQuery.post('/user/reg/initGeetest.do', {}, function(data){
        var desc = "";
        var _config = jQuery.extend({}, config);
        _config.challenge = data.challenge;
        initGeetest(_config, function (captchaObj) {

            captchaObj.appendTo("#"+btnLabelId); // 绑定到id为captcha的元素上

            captchaObj.bindOn("#"+btnLabelId);

            captchaObj.onSuccess(function (data) {
                // 成功回调
                if(params==null){
                    params = {};
                }
                params.geetest_challenge = jQuery("." + btnLabel + " .geetest_challenge").val();
                params.geetest_validate = jQuery("." + btnLabel + " .geetest_validate").val();
                params.geetest_seccode = jQuery("." + btnLabel + " .geetest_seccode").val();
                jQuery.post('/user/reg/verifyGeetest.do', params, function(data){
                    if (data.indexOf('success') > -1) {
                        callback();
                    } else {
                        // 验证错误，刷新验证码
                        desc = "验证码出错，请重新验证";
                        //window.console.log("验证码出错，请重新验证");
                    }

                    if(document.getElementById(errTips)!=null){
                        document.getElementById(errTips).innerHTML=desc;
                    }
                });
            }, 'text');

            captchaObj.getValidate(); // 获取成功后的验证信息，失败是返回false

        });
    }, 'json');
}

function codeBtnClick() {
	var msgType = jQuery('#msgCodeBindBtnSign').val();
	// 发送短信验证码
	if(msgType == 0){
		jQuery('#captcha').click();
	}else if(msgType ==1){
		// 发送语音验证码
		regSendMessageCode();
	}
}

function showGoogleVerificationPart(){
	jQuery("#googleVerificationPart").show();
	jQuery("#showGoogleVerificationOperation").hide();
	jQuery("#phoneVerify").css("border-bottom","none");
	jQuery("#googleVerificationPart").css("border-top-style","dashed");
}

function showOtherVerifySet(){
	jQuery("#otherPersonalSafeSet").show();
	jQuery("#setOtherVerify").hide();
}
